function SDKEVENT() {
    this.CREATEUSERCallbackEvent = document.createEvent("CustomEvent");
    this.CREATEUSERCallbackEvent.initCustomEvent("CREATEUSERCallbackEvent", !1, !1, "");
    this.CREATEORDERCallbackEvent = document.createEvent("CustomEvent");
    this.CREATEORDERCallbackEvent.initCustomEvent("CREATEORDERCallbackEvent", !1, !1, "");
    this.CHANNELSIGNCallbackEvent = document.createEvent("CustomEvent");
    this.CHANNELSIGNCallbackEvent.initCustomEvent("CHANNELSIGNCallbackEvent", !1, !1, "");
    this.USERINFOCallbackEvent = document.createEvent("CustomEvent");
    this.USERINFOCallbackEvent.initCustomEvent("USERINFOCallbackEvent", !1, !1, "");
    this.CREATEJUHEORDERCallbackEvent = document.createEvent("CustomEvent");
    this.CREATEJUHEORDERCallbackEvent.initCustomEvent("CREATEJUHEORDERCallbackEvent", !1, !1, "");
}
SDKEVENT.prototype.CREATEUSERCallback = function (data) {
    this.CREATEUSERCallbackEvent.data = data;
    console.log("SDK CREATEUSERCallbackEvent");
    return document.dispatchEvent(this.CREATEUSERCallbackEvent);
}
SDKEVENT.prototype.CREATEORDERCallback = function (data) {
    this.CREATEORDERCallbackEvent.data = data;
    console.log("SDK CREATEORDERCallbackEvent");
    return document.dispatchEvent(this.CREATEORDERCallbackEvent);
}
SDKEVENT.prototype.CHANNELSIGNCallback = function (data) {
    this.CHANNELSIGNCallbackEvent.data = data;
    console.log("SDK CHANNELSIGNCallbackEvent");
    return document.dispatchEvent(this.CHANNELSIGNCallbackEvent);
}
SDKEVENT.prototype.USERINFOCallback = function (data) {
    this.USERINFOCallbackEvent.data = data;
    console.log("SDK USERINFOCallbackEvent");
    return document.dispatchEvent(this.USERINFOCallbackEvent);
}
SDKEVENT.prototype.CREATEJUHEORDERCallback = function (data) {
    this.CREATEJUHEORDERCallbackEvent.data = data;
    console.log("SDK CREATEJUHEORDERCallbackEvent");
    return document.dispatchEvent(this.CREATEJUHEORDERCallbackEvent);
}
var SDKEVENT = new SDKEVENT();

Array.prototype.indexOf = function (val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};

Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

var Config = {};
Config.APP_NAME = 'myapp';
Config.WAP_ORDER_URL = '//apicqyq.fgcq.info/pay/index';

function GameJuheData(e) {
    this.gameJuhe = e;
};
GameJuheData.prototype.ActiveLog = function () {
    var that = this;
    var data = {
        timestamp: Date.parse(new Date()) / 1000
    }
    data.md5_sign = that.gameJuhe.utils.makeSign(data, that.gameJuhe.cfg.secretKey);
    var e = {
        type: "POST",
        url: that.gameJuhe.cfg.apiUrl + "active/createActivation",
        headers: that.gameJuhe.utils.getPublicHeaders(),
        data: data,
        success: function (res) {
            console.log(res)
        }
    }
    that.gameJuhe.utils.ajax(e);
};
GameJuheData.prototype.CreateLog = function (param) {
    var that = this;
    var data = {
        user_id: that.gameJuhe.cfg.juhe_userid,
        type: 1,
        role_id: param.role_id,
        role_name: param.role_name,
        role_level: param.role_level,
        server_id: param.server_id,
        server_name: param.server_name,
    }
    data.md5_sign = that.gameJuhe.utils.makeSign(data, that.gameJuhe.cfg.secretKey);
    var e = {
        type: "POST",
        url: that.gameJuhe.cfg.apiUrl + "Role/roleConductLog",
        headers: that.gameJuhe.utils.getPublicHeaders(),
        data: data,
        success: function (res) {
            console.log(res)
        }
    }
    that.gameJuhe.utils.ajax(e);
};
GameJuheData.prototype.LoginLog = function (param) {
    var that = this;
    var data = {
        user_id: that.gameJuhe.cfg.juhe_userid,
        type: 3,
        role_id: param.role_id,
        role_name: param.role_name,
        role_level: param.role_level,
        server_id: param.server_id,
        server_name: param.server_name,
    }
    data.md5_sign = that.gameJuhe.utils.makeSign(data, that.gameJuhe.cfg.secretKey);
    var e = {
        type: "POST",
        url: that.gameJuhe.cfg.apiUrl + "Role/roleConductLog",
        headers: that.gameJuhe.utils.getPublicHeaders(),
        data: data,
        success: function (res) {
            console.log(res)
        }
    }
    that.gameJuhe.utils.ajax(e);
};
GameJuheData.prototype.LevelLog = function (param) {
    var that = this;
    var data = {
        user_id: that.gameJuhe.cfg.juhe_userid,
        type: 2,
        role_id: param.role_id,
        role_name: param.role_name,
        role_level: param.role_level,
        server_id: param.server_id,
        server_name: param.server_name,
    }
    data.md5_sign = that.gameJuhe.utils.makeSign(data, that.gameJuhe.cfg.secretKey);
    var e = {
        type: "POST",
        url: that.gameJuhe.cfg.apiUrl + "Role/roleConductLog",
        headers: that.gameJuhe.utils.getPublicHeaders(),
        data: data,
        success: function (res) {
            console.log(res)
        }
    }
    that.gameJuhe.utils.ajax(e);
};
GameJuheData.prototype.HeartLog = function () {
    var that = this;
    var data = {
        user_id: that.gameJuhe.cfg.juhe_userid,
        server_id: that.gameJuhe.cfg.server_id,
        role_id: that.gameJuhe.cfg.role_id,
    }
    data.md5_sign = that.gameJuhe.utils.makeSign(data, that.gameJuhe.cfg.secretKey);
    var e = {
        type: "POST",
        url: that.gameJuhe.cfg.apiUrl + "heart/createLog",
        headers: that.gameJuhe.utils.getPublicHeaders(),
        data: data,
        success: function (res) {
            console.log(res)
        }
    }
    that.gameJuhe.utils.ajax(e);
};
function GameJuheUtils(e) {
    this.gameJuhe = e;
};
GameJuheUtils.prototype.escape2Html = function (str) {
    var arrEntities = {'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"'};
    return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) {
        return arrEntities[t];
    });
}
GameJuheUtils.prototype.setStorAge = function (key, value) {
    try {
        if(window.localStorage){
            localStorage.setItem(key,value);
        }
    } catch(e) {
        console.log(e);
    }
};
GameJuheUtils.prototype.getStorAge = function (key) {
    var value = '';
    try {
        if(window.localStorage){
            value =  localStorage.getItem(key);
         }
    } catch(e) {
        console.log(e);
    }
    return value;
};
GameJuheUtils.prototype.isWeixin = function () {
    var u = navigator.userAgent;
    var e = u.toLowerCase();
    var isWeixin = e.indexOf("micromessenger") > -1;
    return isWeixin;
};
GameJuheUtils.prototype.isIEBelow10 = function () {
    var u = navigator.userAgent;
    return u.indexOf("Trident") > -1 && u.toLowerCase().indexOf("msie") > -1
};
GameJuheUtils.prototype.isIOS = function () {
    return /iPhone|iPod|iPad|Mac/gi.test(navigator.userAgent)
};
GameJuheUtils.prototype.isAndroid = function () {
    return /android|linux/i.test(navigator.userAgent)
};
GameJuheUtils.prototype.isWindowsWechat = function () {
    return /WindowsWechat/gi.test(navigator.userAgent)
};
GameJuheUtils.prototype.isSafari = function () {
    var u = navigator.userAgent;
    console.log(u);
    return u.indexOf("Safari") > -1 && u.indexOf("Chrome") < 1
};
GameJuheUtils.prototype.remove = function(array, val) {
    var index = array.indexOf(val);
    if (index > -1) {
        array.splice(index, 1);
    }
};
GameJuheUtils.prototype.formatParams = function (a) {
    var b, c = [];
    for (b in a)
        a.hasOwnProperty(b) && c.push(encodeURIComponent(b) + "=" + encodeURIComponent(a[b]));
    return c.join("&")
};
GameJuheUtils.prototype.jsonp = function (d) {
    if (d = d || {}, !d.url || !d.callback)
        throw new Error("参数不合法");
    var e, f, g, h;
    e = d.callbackName || ("jsonp_" + Math.random()).replace(".", ""),
    f = document.getElementsByTagName("head")[0],
    d.data[d.callback] = e,
    g = this.formatParams(d.data),
    h = document.createElement("script"),
    f.appendChild(h),
    window[e] = function (json) {
        f.removeChild(h),
        "function" == typeof d.success && d.success(json)
    },
    h.src = d.url + "?" + g,
    d.time && (h.timer = window.setTimeout(function () {
        h.parentElement && f.removeChild(h),
        "function" == typeof d.fail && d.fail({
            code: -100,
            message: "请求超时"
        })
    },d.time))
};
GameJuheUtils.prototype.ajax = function (d) {
    d = d || {};
    d.type = d.type.toUpperCase() || 'POST';
    d.url = d.url || '';
    d.async = d.async || true;
    d.data = d.data || null;    
    d.headers = d.headers || null;
    d.success = d.success || function () {};
    var xmlHttp = null;
    if (XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    } else {
        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
    }var params = [];
    for (var key in d.data){
        params.push(key + '=' + d.data[key]);
    }
    for (var key in d.headers){
        xmlHttp.setRequestHeader(key, d.headers[key]);
    }
    var postData = params.join('&');
    if (d.type.toUpperCase() === 'POST') {
        xmlHttp.open(d.type, d.url, d.async);
        xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
        xmlHttp.send(postData);
    } else if (d.type.toUpperCase() === 'GET') {
        xmlHttp.open(d.type, d.url + '?' + postData, d.async);
        xmlHttp.send(null);
    }
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            console.log(xmlHttp.responseText);
            var json = JSON.parse(xmlHttp.responseText);
            d.success(json);
        }
    };
};
GameJuheUtils.prototype.bin2hex = function (s) {
    var i, l, o = '',n;
    s += '';
    for (i = 0, l = s.length; i < l; i++) {
        n = s.charCodeAt(i).toString(16);
        o += n.length < 2 ? '0' + n : n;
    }
    return o;
};
GameJuheUtils.prototype.GetUUID = function () {
    var obj = this;
    var uuid = obj.getStorAge('uuid');
    if("undefined" == typeof uuid || uuid == null){
        var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
        obj.setStorAge('uuid', uuid);
    }
    return uuid;
};
GameJuheUtils.prototype.getNowFormatDate = function () {
    var date = new Date();
    var month = date.getMonth() + 1;
    var days = date.getDate();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();
    
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (days >= 0 && days <= 9) {
        days = "0" + days;
    }
    if (hours >= 0 && hours <= 9) {
        hours = "0" + hours;
    }
    if (minutes >= 0 && minutes <= 9) {
        minutes = "0" + minutes;
    }
    if (seconds >= 0 && seconds <= 9) {
        seconds = "0" + seconds;
    }
    return date.getFullYear() + month + days + hours + minutes + seconds;
}
GameJuheUtils.prototype.sendChildIframe = function (action, data) {
    document.getElementById(Config.APP_NAME).contentWindow.postMessage(JSON.stringify({
        action: action,
        data: data
    }), '*');
};
GameJuheUtils.prototype.isInArray = function (arr, value) {
    for (var i = 0; i < arr.length; i++) {
        if (value === arr[i]) {
            return true;
        }
    }
    return false;
}
GameJuheUtils.prototype.show = function (objname) {
    var obj = document.getElementById(objname);
    obj.style.display = 'block';
};
GameJuheUtils.prototype.getNextDay = function () {
    var day = new Date();
    day.setDate(day.getDate() + 1);
    return this.format("yyyy-MM-dd", day);
}
GameJuheUtils.prototype.format = function (fmt, date) {
    var o = {
        "M+": date.getMonth() + 1,
        "d+": date.getDate(),
        "h+": date.getHours(),
        "m+": date.getMinutes(),
        "s+": date.getSeconds(),
        "q+": Math.floor((date.getMonth() + 3) / 3),
        "S": date.getMilliseconds()
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
GameJuheUtils.prototype.setCookie = function (key, value, date) {
    var data = {value: value, expirse: new Date(date).getTime()};
    localStorage.setItem(key, JSON.stringify(data));
}
GameJuheUtils.prototype.getCookie = function (key) {
    var data = JSON.parse(localStorage.getItem(key));
    if (data !== null) {
        if (data.expirse != null && data.expirse < new Date().getTime()) {
            localStorage.removeItem(key);
        } else {
            return data.value;
        }
    }
    return null;
}
GameJuheUtils.prototype.isArray = function (e) {
    if (typeof Array.isArray === "function") {
        return Array.isArray(e)
    } else {
        return Object.prototype.toString.call(e) === "[object Array]"
    }
};
GameJuheUtils.prototype.getPublicHeaders = function() {
    var that = this;
    if(that.gameJuhe.cfg.deviceId == ''){
        that.gameJuhe.cfg.deviceId = that.GetUUID();
    }
    if(that.gameJuhe.cfg.platform == ''){
        that.gameJuhe.cfg.platform = '2';
        if(that.isIOS()) that.gameJuhe.cfg.platform = '1';
        if(that.isAndroid()) that.gameJuhe.cfg.platform = '2';
    }

    return {
        packageId: that.gameJuhe.cfg.packageId,
        packageName: that.gameJuhe.cfg.packageName,
        appName: that.gameJuhe.cfg.appName,
        promoteId: that.gameJuhe.cfg.promoteId,
        deviceId: that.gameJuhe.cfg.deviceId,
        platform: that.gameJuhe.cfg.platform,
        appInfoVersion: that.gameJuhe.cfg.appInfoVersion,
        deviceInfo: that.gameJuhe.cfg.deviceInfo,
    };
};
GameJuheUtils.prototype.objKeySort = function (arys) {
    var newkey = Object.keys(arys).sort();
    var newObj = {};
    for (var i = 0; i < newkey.length; i++) {
      newObj[newkey[i]] = arys[newkey[i]]
    }
    return newObj
};
GameJuheUtils.prototype.makeSign = function(data, secretKey) {
    var d = this.objKeySort(data);
    var b = [];
    var s = '';
    for (b in d) {
      if (d.hasOwnProperty(b)) {
        s += d[b]
      }
    }

    var source = s + secretKey;
    console.log('签名原串:', source);
   
    return $.md5(source);
};
GameJuheUtils.prototype.getDeviceId = function() {
    
};
GameJuheUtils.prototype.in_array = function (search, array){
    for(var i in array){
        if(array[i]==search){
            return true;
        }
    }
    return false;
}
function GameJuheIframeDiv(e){
    this.gameJuhe = e
    this.dom = {};
};
GameJuheIframeDiv.prototype.init =function (a, c) {
    this.initIframeDiv(a,c);
    this.initEvent();
};
GameJuheIframeDiv.prototype.initIframeDiv = function (a, c) {
    c = decodeURIComponent(c);
    var id = 'window';
    if(document.getElementById(id)) {
        return;
    }
    var f = document.createElement("div");
    f.id = "window";
    f.className = "iframe_div";
    f.style.background = "#ffffff";
    f.style.overflow = "hidden";
    var g = document.createElement("a");
    g.className = "close";
    g.href = "javascript:;";
    g.innerHTML = "关闭";
    var back = document.createElement("a");
    back.className = "back";
    back.href = "javascript:;";
    var i = document.createElement("i");
    i.className = "iconfont icon-houtuishangyige";
    back.appendChild(this.dom.i = i);
    var nav = document.createElement("div");
    nav.className = "nav clearFix";
    nav.appendChild(this.dom.back = back);
    nav.appendChild(this.dom.closebutton = g);
    f.appendChild(this.dom.nav = nav);
    var h = document.createElement("iframe");
    h.id = a;
    h.width = "100%";
    h.height = "100%";
    h.frameBorder = 0;
    h.sandbox = "allow-scripts allow-top-navigation allow-same-origin allow-forms";
    h.scrolling = "yes";
    h.style.zIndex = "1";
    h.style.background = "#ffffff";
    h.allowtransparency = "yes";
    h.src = c;
    f.appendChild(this.dom.iframe = h);
    (document.body || document.documentElement).appendChild(this.dom.iframe_div = f);
};
GameJuheIframeDiv.prototype.initEvent = function() {
    var e = this;
    this.gameJuhe.ui.on("touchstart mousedown", this.dom.iframe_div,
    function(t) {
        e.dom.iframe_div.remove();
        e.gameJuhe.utils.show(Config.APP_NAME);
    });
};
function GameJuheUI(e){
    this.gameJuhe= e
    this.dom = {};
    this.iframe_div = null;
    this.realname_div = null;
    this.age_tips = null;
};

GameJuheUI.prototype.showIframe = function(a,c) {
    if (!this.iframe_div) this.iframe_div = new GameJuheIframeDiv(this.gameJuhe)
    this.iframe_div.init(a,c);
};

GameJuheUI.prototype.on = function(e, t, a) {
    if (!this.gameJuhe.utils.isArray(t)) t = [t];
    for (var i = 0; i < t.length; i++) { (function(t) {
            var i = function(e) {
                a && a.call(t, e);
                e.preventDefault()
            };
            var n = e.split(" ");
            for (var s = 0; s < n.length; s++) {
                t.addEventListener(n[s], i)
            }
        })(t[i])
    }
};
GameJuheUI.prototype.onClick = function(e, t) {
    if (!this.gameJuhe.utils.isArray(e)) e = [e];
    for (var a = 0; a < e.length; a++) { (function(e) {
            e.addEventListener("click",
            function(a) {
                t && t.call(e, a);
                a.preventDefault()
            })
        })(e[a])
    }
};
GameJuheUI.prototype.onTransitionEnd = function(e, t, a) {
    var i = function(n) {
        if (a) {
            e.removeEventListener("transitionend", i);
            e.removeEventListener("webkitTransitionEnd", i)
        }
        t && t.call(null, n)
    };
    e.addEventListener("transitionend", i);
    e.addEventListener("webkitTransitionEnd", i)
};
function GameJuhe(e) {
    this.utils = new GameJuheUtils(this);
    this.data = new GameJuheData(this);
    this.ui = new GameJuheUI(this);
    this.cfg = {};
};
GameJuhe.prototype.config = function (obj) {
    var b = [];
    for (b in obj)
        obj.hasOwnProperty(b) && (this.cfg[encodeURIComponent(b)] = encodeURIComponent(obj[b]));
};
GameJuhe.prototype.getActiveKey = function () {
    return 'active_' + this.cfg.package_id;
}
GameJuhe.prototype.createOrder = function (param) {
    var that = this;
    var data = {
        user_id: param.user_id,
        product_id: param.product_id,
        server_id: param.server_id,
        server_name: param.server_name,
        role_id: param.role_id,
        role_name: param.role_name,
        props_name: param.product_name,
        body: param.product_desc,
        cp_order_number: param.game_pay_sn,
        price: param.amount,
        is_box: 0,
        extra: param.ext,
    }
    data.md5_sign = that.utils.makeSign(data, that.cfg.secretKey);
    var e = {
        type: "POST",
        url: that.cfg.apiUrl + "order/createOrder",
        headers: that.utils.getPublicHeaders(),
        data: data,
        success: function (res) {
            console.log(res)
            if(res.code == 0){
                if(res.data.pay_way == 2){
                    param.juhe_order_id = res.data.pay_order_number;
                    SDKEVENT.CREATEJUHEORDERCallback(param);
                } else {
                    var url = Config.WAP_ORDER_URL + "?" + GameJuhe.utils.formatParams({
                        pay_order_number: res.data.pay_order_number,
                    });
                    GameJuhe.ui.showIframe('shop', url);
                }
            } else {
                layer.msg(res.msg)
            }
        }
    }
    that.utils.ajax(e);
};
GameJuhe.prototype.queryUserStatus = function (data, callback) {
    var that = this;
    var e = {
        type: "POST",
        url: that.cfg.apiUrl + 'real_name/queryUserStatus',
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function () {}
    };
    obj.utils.ajax(e);
};
GameJuhe.prototype.makeChannelSign = function (data) {
    var obj = this;
    var e = {
        url: Config.API_URL + "/sign",
        data: data,
        callback: "callback",
        time: 6e3,
        success: function (data) {
            if (data.code == 1) {
                SDKEVENT.CHANNELSIGNCallback(data);
            } else {
                var txt = "错误描述: " + data.msg;
                layer.msg(txt);
            }
        },
        fail: function () {}
    };
    obj.utils.jsonp(e);
};
GameJuhe.prototype.createUserInfo = function () {
    var that = this;
    var data = {
        user_id: that.cfg.channel_uid,
        token: that.cfg.channel_token,
        ext: that.cfg.ext,
    }
    data.md5_sign = that.utils.makeSign(data, that.cfg.secretKey);
    var e = {
        type: "POST",
        url: that.cfg.apiUrl + "check/channelLoginCheck",
        headers: that.utils.getPublicHeaders(),
        data: data,
        success: function (res) {
            console.log(res)
            if(res.code == 0){
                SDKEVENT.CREATEUSERCallback(res.data);
            } else {
                layer.msg(res.msg)
            }
        }
    }
    that.utils.ajax(e);
};
GameJuhe.prototype.listener = function (a) {
    if (typeof window.addEventListener != 'undefined') {
        window.addEventListener('message', a, false);
    } else if (typeof window.attachEvent != 'undefined') {
        window.attachEvent('onmessage', a);
    }
};
var GameJuhe = new GameJuhe();
GameJuhe.config(config);
GameJuhe.listener(function (event) {
    try {
        var result = event.data;        
        console.log(result);
        if(typeof result === Object){
            window.postMessage(result)
            return;
        }
        result = JSON.parse(result);
        var origin = event.origin;
        if (result.action == 'pay') {
            GameJuhe.createOrder(result.data);
        }
        if (result.action == 'role_create') {
            GameJuhe.data.CreateLog(result.data);
            GameSdk.push_role_create(result.data, function (event) {
                var data = event.data;
                console.log(data);
            });
        }
        if (result.action == 'role_login') {
            GameJuhe.cfg.role_id = result.data.role_id;
            GameJuhe.cfg.server_id = result.data.server_id;
            GameJuhe.cfg.server_name = result.data.server_name;
            GameJuhe.data.LoginLog(result.data);
            GameSdk.push_role_login(result.data, function (event) {
                var data = event.data;
                console.log(data);
            });
        }
        if (result.action == 'role_level') {            
            GameJuhe.data.LevelLog(result.data);
            GameSdk.push_role_level(result.data, function (event) {
                var data = event.data;
                console.log(data);
            });
        }
        if (result.action == 'reload') {
            location.reload();
        }
        if (result.action == 'loginout') {
            GameSdk.loginout(function (event) {});
        }
        if(result.action == 'clickFocus'){
            document.getElementById(Config.APP_NAME).contentWindow.focus();
        }
    } catch(e) {
        console.log(e);
    }
});
document.addEventListener("CREATEORDERCallbackEvent", function (event) {
    GameSdk.pay({
        user_id: GameJuhe.cfg.channel_uid,
        product_id: event.data.product_id,
        product_name: event.data.product_name,
        product_desc: event.data.product_desc,
        account: event.data.amount,
        app_order_id: event.data.juhe_order_id,
        app_id: GameJuhe.cfg.appId,
        server_id: event.data.server_id,
        server_name: event.data.server_name,
        channel: 'default',
        role_id: event.data.role_id,
        role_name: event.data.playername,
    }, function (event) {
        var data = event.data;
        console.log(data);
    });
});
document.addEventListener("CHANNELSIGNCallbackEvent", function (event) {
});
document.addEventListener("CREATEUSERCallbackEvent", function (event) {
    ("undefined" == typeof GameJuhe.utils.getStorAge(GameJuhe.getActiveKey()) || GameJuhe.utils.getStorAge(GameJuhe.getActiveKey()) == null) && GameJuhe.data.ActiveLog();
    GameJuhe.cfg.juhe_token = event.data.token;
    GameJuhe.cfg.juhe_userid = event.data.user_id;
    //定时发送心跳包
    setInterval(function(){
        GameJuhe.queryUserStatus({
            user_id : GameJuhe.cfg.juhe_userid,
        },function (res) {
            if(res.code == 0){
                if(res.data.status){
                    layer.alert(res.msg, {icon: 1, closeBtn: 0}, function () {
                        GameSdk.loginout(function (event) {});
                    });
                }
            } else {
                layer.msg(res.msg)
            }
        });

        GameJuhe.data.HeartLog({
            server_id : GameJuhe.cfg.server_id,
            role_id : GameJuhe.cfg.role_id,
        })
    },300000);
});
document.addEventListener("USERINFOCallbackEvent", function (event) {
    GameJuhe.cfg.gameUrl = decodeURIComponent(GameJuhe.cfg.gameUrl)
    GameJuhe.cfg.gameUrl = GameJuhe.utils.escape2Html(GameJuhe.cfg.gameUrl);
    if(GameJuhe.cfg.gameUrl.indexOf("?") != -1){
        document.getElementById(Config.APP_NAME).src = GameJuhe.cfg.gameUrl + "&" + GameJuhe.utils.formatParams({
            juhe_userid : GameJuhe.cfg.juhe_userid,
            juhe_token : GameJuhe.cfg.juhe_token,
            app_id : GameJuhe.cfg.appId,
            package_id : GameJuhe.cfg.packageId,
            appInfoVersion: GameJuhe.cfg.appInfoVersion,
            bundleId: GameJuhe.cfg.bundle,
            channelId: GameJuhe.cfg.channel_id,
        })
    } else {
        document.getElementById(Config.APP_NAME).src = GameJuhe.cfg.gameUrl + "?" + GameJuhe.utils.formatParams({
            juhe_userid : GameJuhe.cfg.juhe_userid,
            juhe_token : GameJuhe.cfg.juhe_token,
            app_id : GameJuhe.cfg.appId,
            package_id : GameJuhe.cfg.packageId,
            appInfoVersion: GameJuhe.cfg.appInfoVersion,
            bundleId: GameJuhe.cfg.bundle,
            channelId: GameJuhe.cfg.channel_id,
        })
    }    
});
document.addEventListener("CREATEJUHEORDERCallbackEvent", function (event) {
    var e = {
        type: "POST",
        url: Config.API_DATA_URL + "/get_pay_type",
        data: {
            package_id : GameJuhe.cfg.package_id,
            version : GameJuhe.cfg.version,
            ip : GameJuhe.cfg.ip,
            user_id : GameJuhe.cfg.juhe_userid,
        },
        success: function (data) {
            if (data.message == 'ok') {
                if(data.data.pay_type == 1){
                    SDKEVENT.CREATEORDERCallback(event.data);
                } else if(data.data.pay_type == 2){
                    var url = Config.WAP_ORDER_URL + "?" + GameJuhe.utils.formatParams({
                        package_id: GameJuhe.cfg.package_id,
                        order: event.data.juhe_order_id,
                    });
                    GameJuhe.ui.showIframe('shop', url);
                }
            } else {
                layer.alert(data.message, {icon: 0});
            }
        }
    }
    GameJuhe.utils.ajax(e);
});